﻿using System.Reflection;
using NiuX.AspNetCore.MiniWebApi.Middlewares;

namespace NiuX.AspNetCore.MiniWebApi;

public static class MiniWebApiExtensions
{
    public static void AddActionLocator(this IServiceCollection services)
    {
        var locator = new ActionLocator(services, Assembly.GetEntryAssembly()!);
        services.AddSingleton(locator);
    }

    public static void AddActionLocator(this IServiceCollection services, Assembly assembly)
    {
        var locator = new ActionLocator(services, assembly);
        services.AddSingleton(locator);
    }


    public static IApplicationBuilder UseMiddleware(this IApplicationBuilder app)
    {
        app.UseMiddleware<MyStaticFilesMiddleware>();
        app.UseMiddleware<MyWebAPIMiddleware>();
        return app.UseMiddleware<NotFoundMiddleware>();
    }
}